package com.tulele.vtool.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import com.tulele.vtool.mapper.BBusinessDocumentMapper;
import com.tulele.vtool.model.BBusinessDocument;
import com.tulele.vtool.service.BBusinessDocumentService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商学院小铺文档信息表(BBusinessDocument)表服务实现类
 *
 * @author makejava
 * @since 2020-10-22 15:35:28
 */
@Service("bBusinessDocumentService")
public class BBusinessDocumentServiceImpl implements BBusinessDocumentService {
    @Resource
    private BBusinessDocumentMapper bBusinessDocumentMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BBusinessDocument queryById(Integer id) {
        return this.bBusinessDocumentMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<BBusinessDocument> queryAllByLimit(int offset, int limit) {
        return this.bBusinessDocumentMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param bBusinessDocument 实例对象
     * @return 实例对象
     */
    @Override
    public BBusinessDocument insert(BBusinessDocument bBusinessDocument) {
        this.bBusinessDocumentMapper.insert(bBusinessDocument);
        return bBusinessDocument;
    }

    /**
     * 修改数据
     *
     * @param bBusinessDocument 实例对象
     * @return 实例对象
     */
    @Override
    public BBusinessDocument update(BBusinessDocument bBusinessDocument) {
        this.bBusinessDocumentMapper.update(bBusinessDocument);
        return this.queryById(bBusinessDocument.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.bBusinessDocumentMapper.deleteById(id) > 0;
    }

    /**
     * 查询多条数据
     *
     * @param pageNum 查询起始位置
     * @param pageSize  查询条数
     * @param bBusinessDocument 实例对象
     * @return 对象列表
     */
    @Override
    public PageInfo selectAllByLimit(Integer pageNum, Integer pageSize, BBusinessDocument bBusinessDocument) {

        PageHelper.startPage(pageNum, pageSize);

        bBusinessDocument.setDeleteState(1); //字典状态 0-删除 1-正常
        List<BBusinessDocument> bBusinessDocumentList = this.bBusinessDocumentMapper.queryAll(bBusinessDocument);

        return new PageInfo<BBusinessDocument>(bBusinessDocumentList);

    }
}